package 字符串;

public class longestCommonPrefix {

    public static String longestCommonPrefix(String[] strs) {
        int n=strs.length;
        int minLen=Integer.MAX_VALUE;
        String minLenStr="";
        for(int i=0;i<n;++i){
            if(strs[i].length()<minLen){
                minLen=strs[i].length();
                minLenStr=strs[i];
            }
        }
        int maxLen=0;
        boolean flag=true;
        for (int len=minLen;len>=1;--len){
            String str=minLenStr.substring(0,len);
            flag=true;
            for(int i=0;i<n;++i){
                if(!strs[i].substring(0,len).equals(str)){
                    flag=false;
                    break;
                }
            }
            if(flag) return str;

        }
        return "**";
    }

    public static void main(String[] args) {
        System.out.println(longestCommonPrefix(new String[]{"flower","flow","flight"}));
    }
}
